package com.maple.judegement;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.Test;
/**
* 2013-10-10 17:51:01
*/
public class Judgement {
	/*
	 * 判断str是否为null,如果不为空,再判断str是否为"",只有不是null并且tirm()后不是""时,才返回true
	 * 此方法暂时可以被public static boolean isAvailable(Object... objs)替代
	 */	
	/*public static boolean isAvailable(String... strs)
	{
		for(String s:strs)
		{
			if(s!=null&&(!s.trim().equals("")))
			{}
			else
				return false;
		}
		return true;
	}*/
	
	public static boolean isNull(Object obj)
	{
		if(obj==null)
			return true;
		else
			return false;
	}

	
	
	/**
	 * if the obj is not null, and its size is bigger than 0 
	 * @param obj
	 * @return
	 */
	public static boolean isAvailable(Object... objs)
	{
		if(objs==null)
			return false;		
		for(Object obj:objs)
		{
				if(obj==null)
					return false;
				if(obj.getClass().equals(String.class))
				{
					String s=(String)obj;
					if(s!=null&&(!s.trim().equals("")))
					{
						continue;
					}
					else
						return false;
				}
				Class clazz=obj.getClass();
				//process class type which is child class of Collection
				if(obj instanceof Collection)
				{
					Collection c=(Collection)obj;
					if(c.size()>0)
					{
						continue;
					}else
					{
						return false;
					}
				}
				//process class type which is child class of Map
				if(obj instanceof Map)
				{
					Map map=(Map)obj;
					if(map.size()>0)
					{
						continue;
					}else
					{
						return false;
					}
				}	
		}
		return true;
	}

	/**
	 * 判断是不是图片 Judgement
	 * @param picName
	 * @return
	 */
	public static boolean isPicture(String picName) {
		if(picName==null||"".equals(picName))
			return false;
		int pointIndex=picName.lastIndexOf(".");
		String suffix="";
		if(pointIndex>0)
		{
			suffix=picName.substring(pointIndex+1);
		}else{
			suffix=picName;
		}
		if(suffix.length()==0)
			return false;
		suffix=suffix.toLowerCase();
		boolean isPic="jpg".equals(suffix)||
				"jpeg".equals(suffix)||
				"tiff".equals(suffix)||
				"gif".equals(suffix)||
				"pcx".equals(suffix)||
				"tga".equals(suffix)||
				"exif".equals(suffix)||
				"fpx".equals(suffix)||
				"svg".equals(suffix)||
				"psd".equals(suffix)||
				"cdr".equals(suffix)||
				"pcd".equals(suffix)||
				"dxf".equals(suffix)||
				"ufo".equals(suffix)||
				"ps".equals(suffix)||
				"ai".equals(suffix)||
				"raw".equals(suffix);
		return isPic;
	}

	/**
	 * 判断手机号是否符合规范
	 * @param phoneNumber 格式为13264191616,11位数字
	 * @return
	 */
	public static  boolean isAvailableMobilePhoneNumber(String phoneNumber)
	{
		Pattern p=Pattern.compile("^1\\d{10}$");
		Matcher m=p.matcher(phoneNumber);
		return m.matches();
	}

}
